package my.examples.clsunload;

/**
 * 配置jvm参数：-Xlog:class+load=info -Xlog:class+unload=info
 */
public class ClassUnload {

    public static void main(String[] args) {
        var workDir = System.getProperty("user.dir");
        System.out.println("用户的当前工作目录:/n" + workDir);
        var path = workDir + "/class-unload/target/classes/my/examples/clsunload/Dd.class";
        ttt(path);
        while (true) {
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.gc();
        }
    }

    private static void ttt(String path) {
        var mcl = new MyClassLoader();
        var targetCls = mcl.load("my.examples.clsunload.Dd", path);
        var c = targetCls.getDeclaredConstructors()[0];
        /*try {
            var t = c.newInstance();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }*/
    }

}
